Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
How to insert an "Select All" option in dropdownlist?

I have a dropdown list with a filter for IN and OUT values. Here everything works.

<select class="form-select" style="max-width: 100px" [ngModel]="selectedBrand" (ngModelChange)="onChangeType($event)">
    <option [value]="'IN'">IN</option>
    <option [value]="'OUT'">OUT</option>
</select>

TS

  public selectedBrand: any;
  public onChangeType(type: any) {
    this.selectedBrand = type;
    console.log(this.selectedBrand);

    this.filteredCustomer = this.customerTransferts.filter(
        (item) => item.type === this.selectedBrand
    );
    console.log(this.filteredCustomer);
  }

I would now like to add a SELECT ALL to retrieve the elements of IN or OUT.

What am I missing in my code, please?

Thanks for your help.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can either have a function to remove the filter like so:

resetFilter() {
    this.selectedBrand = '';
    this.filteredCustomer = this.customerTransferts
}

You could call this with a button click or whatever you like.


Or you can put another option in your dropdown, and check for it in the onChangeType method.

<select class="form-select" style="max-width: 100px" [ngModel]="selectedBrand" (ngModelChange)="onChangeType($event)">
    <option [value]="'ALL'">ALL</option>
    <option [value]="'IN'">IN</option>
    <option [value]="'OUT'">OUT</option>
</select>
public onChangeType(type: any) {
    if (type === 'ALL') {
      this.filteredCustomer = this.customerTransferts;
      return;
    }

    this.selectedBrand = type;
    console.log(this.selectedBrand);

    this.filteredCustomer = this.customerTransferts.filter(
        (item) => item.type === this.selectedBrand
    );
    console.log(this.filteredCustomer);
  }

Also you should change your ngModel to two way binding [(ngModel)]

<select class="form-select" style="max-width: 100px" [(ngModel)]="selectedBrand" (ngModelChange)="onChangeType($event)">

Then it will automatically be synced with the selectedBrand property - both ways.

So you can remove this.selectedBrand = type from onChangeType().

public onChangeType(type: any) {
    if (type === 'ALL') {
      this.filteredCustomer = this.customerTransferts;
      return;
    }

    this.filteredCustomer = this.customerTransferts.filter(
        (item) => item.type === type
    );
  }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda